Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added a convenience method that will return an existing item du… #342

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Sep 27, 2024

…ring a check for insertion

Issue being fixed or feature implemented

This change implements a new function insert_if_not_exists_return_existing_element in GroveDB. The function allows for the insertion of an element if it does not already exist at the specified path and key. If the element already exists, the function returns the existing element instead of performing an insertion. This is useful for scenarios where we want to avoid overwriting existing data but still need to confirm its presence.

What was done?

• Added a new function insert_if_not_exists_return_existing_element to GroveDB.
• This function checks if an element already exists at the given path and key.
• If the element exists, it returns the existing element.
• If the element does not exist, it inserts the new element and returns None.

How Has This Been Tested?

Breaking Changes

This change does not introduce any breaking changes.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced a new method to insert elements into the database only if they do not already exist, returning the existing element if found.
    • Added a new field to support this functionality in the versioning structure.
  • Bug Fixes

    • Updated method signatures for clarity on return types.

Copy link

coderabbitai bot commented Sep 27, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a new feature in the GroveDB system that allows for inserting elements into the database conditionally. A new field, insert_if_not_exists_return_existing_element, has been added to the GroveDBOperationsInsertVersions struct, enhancing the versioning of insert operations. Additionally, a public method insert_if_not_exists_return_existing_element has been implemented in the GroveDb to facilitate this functionality, enabling the retrieval of an existing element if it is found during the insertion process.

Changes

File Path Change Summary
grovedb-version/src/version/grovedb_versions.rs Added field pub insert_if_not_exists_return_existing_element: FeatureVersion to GroveDBOperationsInsertVersions struct.
grovedb-version/src/version/v1.rs Added new field insert_if_not_exists_return_existing_element: 0 in GroveVersion structure within GroveDBOperationsInsertVersions.
grovedb/src/operations/insert/mod.rs Introduced public method insert_if_not_exists_return_existing_element in GroveDb for conditional insertion and retrieval of existing elements. Updated signature of insert_if_not_exists method.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GroveDb
    participant Database

    User->>GroveDb: insert_if_not_exists_return_existing_element(path, key, element)
    GroveDb->>Database: get_raw_optional(key)
    alt Element exists
        Database-->>GroveDb: existing_element
        GroveDb-->>User: return existing_element
    else Element does not exist
        GroveDb->>Database: insert(element)
        Database-->>GroveDb: insertion_success
        GroveDb-->>User: return None
    end
Loading

🐇 In the Grove where data plays,
New fields and methods brighten the days.
With a hop and a skip, we check and we see,
If an element's there, then it's returned with glee!
Insert with care, let the old ones stay,
In our GroveDB, all elements at play! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@QuantumExplorer
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Sep 27, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (3)
grovedb-version/src/version/v1.rs (1)

97-97: LGTM! Consider adding a comment for clarity.

The addition of the insert_if_not_exists_return_existing_element field is consistent with the PR objectives and follows the existing structure. The initialization to 0 aligns with other fields, likely representing the initial version of this operation.

Consider adding a brief comment above this field to explain its purpose, similar to:

/// Version for the operation that inserts an element if it doesn't exist and returns the existing element if it does.
insert_if_not_exists_return_existing_element: 0,

This would enhance code readability and maintain consistency with any existing documentation practices in the codebase.

grovedb-version/src/version/grovedb_versions.rs (2)

138-138: LGTM! Consider adding a doc comment for clarity.

The addition of the insert_if_not_exists_return_existing_element field is consistent with the existing structure and aligns well with the PR objectives. It extends the functionality without breaking existing features.

Consider adding a brief doc comment to explain the purpose of this new field, similar to:

/// Tracks the version of the feature that allows inserting an element if it doesn't exist
/// and returns the existing element if it does.
pub insert_if_not_exists_return_existing_element: FeatureVersion,

This would improve the self-documentation of the code and make it easier for other developers to understand the purpose of this field.


Line range hint 1-238: Overall, the change is well-implemented and consistent.

The addition of the insert_if_not_exists_return_existing_element field to the GroveDBOperationsInsertVersions struct is a focused and non-disruptive change. It extends the functionality of GroveDB's insert operations in a manner consistent with the existing code structure and naming conventions.

As the GroveDB system continues to evolve, consider periodically reviewing these version structs to ensure they remain manageable. If the number of fields grows significantly, it might be worth considering grouping related features into sub-structs for better organization and maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fd2f134 and 1020875.

📒 Files selected for processing (3)
  • grovedb-version/src/version/grovedb_versions.rs (1 hunks)
  • grovedb-version/src/version/v1.rs (1 hunks)
  • grovedb/src/operations/insert/mod.rs (2 hunks)
🔇 Additional comments (1)
grovedb-version/src/version/v1.rs (1)

Line range hint 1-200: Overall assessment: The change is well-integrated and aligned with PR objectives.

The addition of the insert_if_not_exists_return_existing_element field to the GroveDBOperationsInsertVersions struct is a minimal, non-breaking change that enhances the functionality of insert operations as described in the PR objectives. The implementation is consistent with the existing code structure and versioning approach.

To ensure that this change is properly integrated across the codebase, consider running the following verification script:

This script will help verify that the new operation is properly implemented, used, and tested across the codebase.

grovedb/src/operations/insert/mod.rs Outdated Show resolved Hide resolved
grovedb/src/operations/insert/mod.rs Outdated Show resolved Hide resolved
grovedb/src/operations/insert/mod.rs Outdated Show resolved Hide resolved
grovedb/src/operations/insert/mod.rs Outdated Show resolved Hide resolved
QuantumExplorer and others added 4 commits September 28, 2024 01:43
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@QuantumExplorer QuantumExplorer merged commit e813cad into develop Sep 27, 2024
8 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/InsertIfNotExistsReturnExistingElement branch September 27, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant